package com.ysd.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ysd.Dao.Impl.CompanyDaoImpl;
import com.ysd.Dao.Impl.NewsDaoImpl;
import com.ysd.Dao.Impl.UserDaoImpl;
import com.ysd.entity.Company;
import com.ysd.entity.News;
import com.ysd.entity.User;
import com.ysd.util.Result;

public class MessageServlet extends HttpServlet {
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		String userName = request.getParameter("userName");
		String userPhone = request.getParameter("userPhone");
		String userEmail = request.getParameter("userEmail");
		String messageContent = request.getParameter("messageContent");
		User user = new User(userName,userPhone,userEmail,messageContent);
		response.setCharacterEncoding("UTF-8");
		
		
		UserDaoImpl uDao =new UserDaoImpl();
		PrintWriter out = response.getWriter();
		
		
		int n= uDao.addMessage(user);
		if (n > 0) {//成功
			out.print(Result.toClient(true, "留言成功",""));
		} else {//失败
			out.print(Result.toClient(false, "留言失败","服务器异常"));
		}
		out.flush();
		out.close();
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
